package com.thread;

/**
 * @author :admin
 * @description: TODO edit class Description
 * @create date: 2019/4/3 16:05
 */
public class ThreadStu {
    private int num;

    public void addNum(String name) {
        int num;    //该变量为方法内局部变量一定是线程安全，并且覆盖了全局变量num，如注释该行，全局变量num存在线程安全，
        try {
            if (name.equals("a")) {
                num = 100;
                System.out.println("a set over!");
                Thread.sleep(1000);
            }else {
                num=200;
                System.out.println("b set over!");
            }
            System.out.println(name+" num = "+num);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}

